#ifndef __GMLAN_H__
#define __GMLAN_H__

#include "stm32f10x.h"
#include "vehicle.h"

#define GMLAN_SERVICE_ID_DYNAMIC_PID_DEFINE         0x2c
#define GMLAN_SERVICE_ID_MODE_TWENTY_TWO            0x22
#define GMLAN_SERVICE_ID_READ_STATIC_DATA           0x1a

#define GMLAN_SERVICE_ID_READ_DYNAMIC_DATA          0xaa
#define GMLAN_SERVICE_ID_READ_DYNAMIC_DATA_STOP     0x00
#define GMLAN_SERVICE_ID_READ_DYNAMIC_DATA_ONESHOT  0x01
#define GMLAN_SERVICE_ID_READ_DYNAMIC_DATA_SLOW     0x02
#define GMLAN_SERVICE_ID_READ_DYNAMIC_DATA_MEDIUM   0x03
#define GMLAN_SERVICE_ID_READ_DYNAMIC_DATA_FAST     0x04


typedef struct __gmlan_data {
    uint16_t tx_id;
    uint16_t rx_id;
    uint16_t rx_id2;
    uint8_t len;
    uint8_t service_id;
    uint8_t index;
    uint8_t cmd[2];
//    uint8_t read_mode;
} gmlan_data;

typedef struct __gmlan_recv {
    uint8_t data[16];
    uint8_t offset;
    uint8_t size;
} gmlan_recv;

typedef struct __gmlan_codes_cmd {
    uint16_t tx_id;
    uint16_t rx_id;
    uint8_t len;
    uint8_t id1;
    uint8_t id2;
    uint8_t cmd;
} gmlan_codes_cmd;

typedef struct __gmlan_codes_result {
    uint16_t id;
    uint16_t codes[CODE_MAX_SIZE];
    uint8_t count;
} gmlan_codes_result;

void gmlan_init(void);
uint8_t gmlan_ioctl(gmlan_data *data, gmlan_recv *recv);
uint8_t gmlan_get_codes(gmlan_codes_cmd *cmd, gmlan_codes_result *result);

#endif
